﻿<?php

      $id = $_GET['id'];
      // /*查询正在编辑数据的数据信息*/
      $sqlb = "select * from `roles` where `id`=$id";
      $relb =mysqli_query($link,$sqlb);
      $db = mysqli_fetch_assoc($relb);
      // print_r($db);die;
      $power = explode(',',$db['power']);

      $status = $db['status'];










      //print_r($power);die;

      // /*查询父级为0*/
      $sql = "select * from `power` where `pid`=0";
      $rel =mysqli_query($link,$sql);
      while($d = mysqli_fetch_assoc($rel)){
            $date[] =$d;
      }
      //print_r($date);die;
       /*查询子级*/
      $sqla = "select * from `power` where `pid`!=0";
      $rela =mysqli_query($link,$sqla);
      while($dd = mysqli_fetch_assoc($rela)){
            $datea[] =$dd;
      }




       if(!empty($_POST['username'])&&!empty($_POST['child'])){
        $name = $_POST['username'];
        $power = implode(',',$_POST['child']);
        $status = $_POST['yes'];

            $sql = "update `roles` set `name`='$name',`power`='$power',`status`=$status where `id`=$id";
            mysqli_query($link,$sql);
            $row = mysqli_affected_rows($link);
            if($row>0){echo "<script>alert('角色修改成功');location.href='index.php?c=role&a=list&admin=1';</script>";}else{echo "<script>alert('角色修改失败');history.go(-1);</script>";}
        //echo $power;die;




      }
      //print_r($datea);die;





		include(CON_VIEW.$q.'/common.html');
?>